package com.greejoy.score;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import com.greejoy.score.service.WebsocketService;

import java.util.HashMap;

public class MyApplication extends Application {

    private static MyApplication app;
    public HashMap<String, String> dataMap = new HashMap<>();

    @Override
    public void onCreate() {
        super.onCreate();

        SharedPreferences sharedPreferences = getSharedPreferences("config", Context.MODE_PRIVATE);
        String httpUrl = sharedPreferences.getString("httpUrl", "http://192.168.188.200:8088");
        String wsUrl = sharedPreferences.getString("wsUrl", "ws://192.168.188.200:8088/js/ws/server");
        dataMap.put("httpUrl", httpUrl);
        dataMap.put("wsUrl", wsUrl);
        app = this;

        Intent intent = new Intent(this, WebsocketService.class);
        startService(intent);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        Intent intent = new Intent(this, WebsocketService.class);
        stopService(intent);
    }

    public static MyApplication getInstance(){
        return  app;
    }
}
